<?php

class SelectModel extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function selectData($table) {
        return $this->db->get($table);
    }

    
    /**
     * @param array $post
     * 
     * @return bool
     */
    public function add_by_user_post($post) {
        $this->load->library('form_validation');

        //$this->validate_firstname();
        // echo '<pre>' . print_r($validattion, 1) . '</pre>';
        ///echo '<pre>' . print_r($post, 1) . '</pre>';
        ///exit;
        echo $this->form_validation->run();
        exit;


        //validattion here
        // $insert_data = [
        // 	'Firstname' => $post['firstname'],
        // 	'Lastname'	=> $post['lastname'].
        // 	'Username'	=> $post['username'],
        // 	'Email'		=> $post['email'],
        // 	'Password'	=> md5($post['password'])
        // ]; 		
        // $this->db->insert($this->table, $insert_data);
    }

    public function check_credentials($username, $password) {
        $this->db->select('user_id, firstname, lastname, group6_tbl_role.role_id, role_name')
                ->join('group6_tbl_role', 'group6_tbl_role.role_id = ' . $this->table . '.role_id')
                ->where('username', $username)
                ->where('password', md5($password))
                ->where($this->table . '.enable', true)
                ->limit(1);

        $query = $this->db->get($this->table);

        if ($query->num_rows() > 0) {
            $row = $query->row();
            $this->id = $row->user_id;
            $this->firstname = $row->firstname;
            $this->lastname = $row->lastname;
            $this->role_id = $row->role_id;
            $this->role = $row->role_name;

            return true;
        }

        return false;
    }

    public function error() {
        return $this->error;
    }

}